import os
import sys
from selenium import webdriver
from time import sleep
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.service import Service as FirefoxService
from selenium.webdriver.common.action_chains import ActionChains


class LikeShopTest():
    def __init__(self) -> None:

        driver_path = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(sys.executable)))),
                                   'geckodriver.exe')
        service = FirefoxService(executable_path=driver_path)
        options = webdriver.FirefoxOptions()
        self.browser = webdriver.Firefox(service=service, options=options)

    def test_1(self):
        self.browser.get('http://likeshop.abc/admin/account/login.html')
        sleep(2)
        # 定位到账户框
        self.browser.find_element(By.NAME, 'account').send_keys('admin')
        # 定位密码框
        self.browser.find_element(By.NAME, 'password').send_keys('123456')
        # 定位验证码输入框
        self.browser.find_element(By.NAME, 'code').send_keys('1111')
        # 定位登录按钮
        self.browser.find_element(By.ID, 'login').click()

        sleep(3)


if __name__ == '__main__':
    likeShopTest = LikeShopTest()
    likeShopTest.test_1()
